package com.example.cloudconsumer.service;

import com.example.cloudconsumer.config.FeignConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Auther: SPL
 * @Date: 2019-07-24 11:11
 * @Description: - Feign接口式远程调用
 */
//name:远程服务名（多服务同名即负载均衡），及spring.application.name配置的名称，fallback：熔断器，configuration: 额外配置
@FeignClient(name = "cloud-server-cn",fallback = RemoteService.RemoteServiceHystrix.class, configuration = FeignConfig.class)
public interface RemoteService {

    @RequestMapping("/test")
    String callMethod();


    /**
     * 熔断器
     */
    @Component
    class RemoteServiceHystrix implements RemoteService{
        @Override
        public String callMethod() {
            return "服务调用失败：这是熔断器，Hystrix";
        }
    }

}
